<?php
/*********************************************
  CPG Dragonfly™ CMS
  ********************************************
  Copyright © 2004 - 2007 by CPG-Nuke Dev Team
  http://dragonflycms.org

  Dragonfly is released under the terms and conditions
  of the GNU GPL version 2 or any later version
**********************************************/
if (!defined('ADMIN_PAGES')) { exit; }
if (!can_admin()) { cpg_error('Access Denied'); }
//Dragonfly::getKernel()->L10N->load('Your_Account');

class Dragonfly_Admin_Auth extends \Poodle\Auth\Admin
{
	public function GET()
	{
		$GLOBALS['pagetitle'] .= ' '._BC_DELIM.' Authentication';

		$OUT = Dragonfly::getKernel()->OUT;
		$OUT->captcha = extension_loaded('gd');
		if (function_exists('imagettftext'))
		{
			$fontlist = array();
			$handle = opendir(CORE_PATH.'fonts');
			while ($file = readdir($handle)) {
				if (preg_match('#\.ttf$#',$file)) { $fontlist[$file] = substr($file,0 , -4); }
			}
			closedir($handle);
			natcasesort($fontlist);
			array_unshift($fontlist, '[system]');
			$OUT->captcha_fonts = $fontlist;
		}

		parent::GET();
	}

	public function POST()
	{
		if (empty($_POST['admin_cookie']['name']) || empty($_POST['auth_cookie']['name'])) {
			cpg_error(sprintf(_ERROR_NOT_SET, 'Cookie name'));
		}

		$CFG = Dragonfly::getKernel()->CFG;

		$CFG->set('cookie',       'admin',       $_POST['cookie']['admin']);
		$CFG->set('admin_cookie', 'name',        $_POST['cookie']['admin']);
		$CFG->set('admin_cookie', 'allow',       $_POST['admin_cookie']['allow']);
		$CFG->set('admin_cookie', 'cipher',      $_POST['admin_cookie']['cipher']);
		$CFG->set('admin_cookie', 'cryptkey',    $_POST['admin_cookie']['cryptkey']);
		$CFG->set('admin_cookie', 'compression', $_POST['admin_cookie']['compression']);
		$CFG->set('admin_cookie', 'timeout',     intval($_POST['admin_cookie']['timeout']));

		$CFG->set('cookie',      'member',      $_POST['cookie']['admin']);
		$CFG->set('auth_cookie', 'name',        $_POST['cookie']['admin']);
		$CFG->set('auth_cookie', 'allow',       $_POST['auth_cookie']['allow']);
		$CFG->set('auth_cookie', 'cipher',      $_POST['auth_cookie']['cipher']);
		$CFG->set('auth_cookie', 'cryptkey',    $_POST['auth_cookie']['cryptkey']);
		$CFG->set('auth_cookie', 'compression', $_POST['auth_cookie']['compression']);
		$CFG->set('auth_cookie', 'timeout',     intval($_POST['auth_cookie']['timeout']));

		if (extension_loaded('gd'))
		{
			$CFG->set('global',   'sec_code',  array_sum($_POST['sec_code']['show']));
			$CFG->set('sec_code', 'back_img',  !empty($_POST['sec_code']['back_img']));
			if (function_exists('imagettftext'))
			{
				$CFG->set('sec_code', 'font',      $_POST['sec_code']['font']);
				$CFG->set('sec_code', 'font_size', intval($_POST['sec_code']['font_size']));
			}
		}

		parent::POST();
	}
}

$class = new Dragonfly_Admin_Auth;
$class->$_SERVER['REQUEST_METHOD']();
